// GreenTriangle.cpp: implementation of the CGreenTriangle class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "8085.h"
#include "GreenTriangle.h"
#include <cmath>                    

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////


CGreenTriangle::CGreenTriangle()
{
    Init();
    SetProperty(0,0,0);
}

CGreenTriangle::CGreenTriangle(CPoint basePt,int len, int angle)
{
    Init();
    SetProperty(basePt,len,angle);
}

CGreenTriangle::~CGreenTriangle()
{

}

void CGreenTriangle::SetProperty(CPoint basePt, int len, int angle)
{
    m_Base = basePt;
    m_nLength = len;
    m_nAngle = angle;
    int sineValue = int(len*sin(angle*PI/180));
    int cosineValue = int(len*cos(angle*PI/180));

    m_Points[0] = CPoint(basePt.x-(cosineValue/2),basePt.y+sineValue/2);
    m_Points[1] = CPoint(basePt.x+(cosineValue/2),basePt.y-sineValue/2);
    m_Points[2] = CPoint(basePt.x-sineValue,basePt.y-cosineValue);
}

void CGreenTriangle::SetProperty(int x,int y, int len, int angle)
{
    m_Base.x = x;
    m_Base.y = y;
    m_nLength = len;
    m_nAngle = angle;
    int sineValue = int(len*sin(angle*PI/180));
    int cosineValue = int(len*cos(angle*PI/180));

    m_Points[0] = CPoint(x-(cosineValue/2),y+sineValue/2);
    m_Points[1] = CPoint(x+(cosineValue/2),y-sineValue/2);
    m_Points[2] = CPoint(x-sineValue,y-cosineValue);
}

int CGreenTriangle::Draw(CDC * pDC,BOOL bErase)
{
    CBrush fill(bErase ? pDC->GetBkColor() : m_FillColour);
    // CPen pen(PS_SOLID,1,(bErase ? pDC->GetBkColor() : m_BorderColour));
	CPen pen(PS_SOLID,1,( m_BorderColour ));
	CBrush *saveBrush = pDC->SelectObject(&fill);
    CPen *savePen = pDC->SelectObject(&pen);

    pDC->Polygon(m_Points,3);

    pDC->SelectObject(saveBrush);    // restore the saved brush
    pDC->SelectObject(savePen);
    return GetVirtualLength();
}

void CGreenTriangle::Init()
{
    COLORREF c = RGB(0,200,0);
    SetBorderColour( RGB(0,0,0) );
    SetFillColour(c);
}

CPoint & CGreenTriangle::GetProperty(int & len, int & angle)
{
    len = m_nLength;
    angle = m_nAngle;
    return m_Base;
}
